package aTowerDefense;

import java.util.Observer;

import javax.swing.JMenuItem;

public class StyleMenu extends JMenuItem {

	private String _currentStyle = "Forest";
	//JMenuItem _styleSelection = ;
	//I forgot what the JMenuItem was for.
	
	
	//I had this stuff based on the UML, but decided to scrap it since
	//this was the implementation of the Observer, not the Subject.
	
	/*
	public void RegisterObserver(Observer SMObserver) {
		Observer sub = SMObserver;
		sub.attach(this);
		
	}
	

	public void RemoveObserver(Observer SMObserver) {
		Observer sub = SMObserver;
		sub.detach(this);
		
	}
	
	public void NotifyObserver() {
		sub.update();
	}
	*/
	
	
	
	
	//The following is the implementation of the Subject
	
	private Observer[] observers = new Observer[9];
	
	private int totalObs = 0;

	public void attach( Observer o ) {
	    observers[totalObs++] = o;
	}

	public String getState() {
	    return _currentStyle;
	}
	
	
	//Extra method we may need.
	/*
	public void StyleChange(String nextStyle) {
		_currentStyle = nextStyle;
		notify();
		
	}
	*/
	  
	public void ChangeToForest() {
		_currentStyle = "Forest";
		notify();

	}
	
	public void ChangeToDesert() {
		_currentStyle = "Desert";
		notify();
	}
	
	public void ChangeToCave() {
		_currentStyle = "Cave";
		notify();
	}
	
	
	public void notify() {
		for (int i=0; i < totalObs; i++) {
	    	observers[i].update();
	    }
	}
	
	//So, I think I need concrete classes to get rid of this error.
	
}
